/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.spielo.crystaldesigner.dao;

import com.spielo.crystaldesigner.property.PropertyHolder;
import java.io.File;
import java.util.ArrayList;
import java.util.Vector;

/**
 *
 * @author Bernhard Reads all screens from the folder
 */
public class StyleReader {

    private PropertyHolder properties = PropertyHolder.getInstance();

    public Vector<String> getSubfolderList() {
        String pathToPackage = (String) properties.getProperty("path");
        String pathToStyles = pathToPackage + File.separator + "Resources" + File.separator + "Styles";
        Vector<String> list = new Vector<>();
        list.add("root");
        File styleFolder = new File(pathToStyles);
        File[] content = styleFolder.listFiles();
        System.out.println();
        for (File f : content) {
            if (f.isDirectory()) {
                list.add(f.getName());
            }
        }


        return list;
    }

    public Vector<String> getStyleList(String subfolder) {
        String pathToPackage = (String) properties.getProperty("path");
        String pathToStyles = pathToPackage + File.separator + "Resources" + File.separator + "Styles";
        Vector<String> list = new Vector<>();

        String path = "";

        if (!subfolder.equals("root") && subfolder.length() > 0) {
            path = pathToStyles + File.separator + subfolder;
        } else {
            path = pathToStyles;
        }


        File styleFolder = new File(path);

        File[] content = styleFolder.listFiles();

        for (File f : content) {
            if (f.getAbsolutePath().endsWith(".xaml")) {
                String name = f.getName();
                name = name.substring(0, name.lastIndexOf("."));
                list.add(name);
            }
        }

        System.out.println(list);
        return list;
    }

    public static void main(String[] args) {
        PropertyHolder properties = PropertyHolder.getInstance();
        properties.addProperty("path", "D:\\schule\\diplomarbeit\\CMOD User Interface 4.1.20.3241\\");
        StyleReader sr = new StyleReader();
        System.out.println(sr.getStyleList(""));
    }

}
